﻿#region using
using System;
using System.Collections.Generic;
#endregion

namespace AwesomeTanks.Sources.GameElements.ControllerGame
{
    /// <summary>
    /// This class permits to know if the Game is finish or not
    /// </summary>
    public static class GameController
    {
        #region Methods

        /// <summary>
        /// Checks the time.
        /// </summary>
        /// <returns></returns>
        public static Boolean TimeIsUp()
        {
            return AwesomeTanks.Sources.Screens.GameplayScreen.TimerGame.GameFinish;
        }

        /// <summary>
        /// Checks there is more than one team alive.
        /// </summary>
        /// <returns></returns>
        public static Boolean CheckMoreThanOneTeamAlive()
        {
            List<Team> team = AwesomeTanks.Sources.Screens.GameplayScreen.listTeam;
            List<Boolean> PlayerAliveInTeam = new List<Boolean>();
            int AliveTeam = 0;
            //fill ListPlayerAliveInTeam
            for (int i = 0; i < team.Count; i++)
            {
                PlayerAliveInTeam.Add(false);
                for (int j = 0; j < team[i].ListPlayers.Count; j++)
                {
                    if (team[i].ListPlayers[j].Tank != null)
                    {
                            PlayerAliveInTeam[i] = true;
                    }
                }
            }

            //CheckMoreThanOneTeamAlive
            foreach(Boolean b in PlayerAliveInTeam)
            {
                if (b) AliveTeam++;
            }
            return (AliveTeam >= 2) ? true : false;
        }

        #endregion
    }
}
